package com.servlet;

import com.pojo.User;
import com.service.apply.ApplyServiceImpl;
import com.util.Constant;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ApplyAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object o = req.getSession().getAttribute(Constant.USER_SESSION);

        int userId = ((User)o).getUserId();

        String applyName = req.getParameter("applyName");
        String applyExplain = req.getParameter("applyExplain");
        String applyAddress = req.getParameter("applyAddress");
        String msg = "";
        ApplyServiceImpl applyService = new ApplyServiceImpl();
        int flag = applyService.ApplyAdd(userId, applyName, applyAddress, applyExplain);
        if(flag > 0){
            msg = "发布成功";
            req.getRequestDispatcher("/jsp/allgoods.jsp").forward(req,resp);
        }else{
            msg = "发布失败";
            req.getRequestDispatcher("/jsp/addapply.jsp").forward(req,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
